package com.wanmait.wanmarecruit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wanmait.wanmarecruit.entity.EducationalExperience;
import com.wanmait.wanmarecruit.service.StudentCadreExperienceService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wanmarecruit.mapper.StudentCadreExperienceMapper;
import com.wanmait.wanmarecruit.entity.StudentCadreExperience;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class StudentCadreExperienceServiceImpl extends ServiceImpl<StudentCadreExperienceMapper, StudentCadreExperience> implements StudentCadreExperienceService {

    @Override
    public List<StudentCadreExperience> getCadreByUserId(Integer userId) {
        LambdaQueryWrapper<StudentCadreExperience> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StudentCadreExperience::getUserId,userId);
        return this.list(queryWrapper);
    }

    @Override
    public void saveStudentCadreExperiences(Integer userId, List<StudentCadreExperience> experienceList) {
        experienceList.forEach(educationalExperience -> educationalExperience.setUserId(userId));
        LambdaQueryWrapper<StudentCadreExperience> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StudentCadreExperience::getUserId,userId);
        this.remove(queryWrapper);
        this.saveBatch(experienceList);
    }
}
